<?php

namespace App\Console\Commands\CallingCards;

use App\Models\FeishuCallingCard\FeishuCallingCard;
use App\Service\CallingCards\CardService;
use Illuminate\Console\Command;

class RefreshWxShareImg extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'feishuCallingCards:refreshWxShareImg';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '更新为空的微信分享图';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        FeishuCallingCard::query()
//            ->where('wxShareImg', '')//分页后面数据查不到了。。。
            ->orderBy('id', 'asc')
            ->chunk(
                100, function ($cards) {
                foreach ($cards as $card) {
                    // 更新为空的微信分享图
                    if ($card->wxShareImg == '') {
                        CardService::updateWxShareImg($card);
                    }
                }
            }
            );
    }
}
